﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Service
{
    internal class ChangePin : ICommand
    {
        DataLayer.DBFacade DB;
        Model.Account account;
        private int oldPin;
        public ChangePin(Model.Account account, int oldPin)
        {
            DB = new DataLayer.DBFacade();
            this.account = account;
            this.oldPin = oldPin;
        }

        public bool Execute()
        {
            string query = "update account set PIN=" + account.PIN + " where AccountNo='" + account.AccountNumber + "' and PIN=" + oldPin;//update with new pin
            return DB.Execute(query) > 0;
        }

        public bool Undo()
        {
            string query = "update account set PIN=" + oldPin + " where AccountNo='" + account.AccountNumber + "' and PIN=" + account.PIN; //update with old pin
            return DB.Execute(query) > 0;
        }
    }
}